package com.xieshue.im.mq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;

import java.util.UUID;

/**
 * Created by Administrator on 2018/1/13.
 */
public class ImProducer {

    private static final Logger logger = LoggerFactory.getLogger(ImProducer.class);

    public static void main(String[] args) throws Exception {
        // send something
        ConnectionMq mq = ConnectionMq.getInstance();
        RabbitTemplate template = new RabbitTemplate(mq.createFactory());
        template.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
            @Override
            public void confirm(CorrelationData correlationData, boolean ack, String cause) {
                logger.info(" 消息id:" + correlationData);
                if (ack) {
                    logger.info("消息发送确认成功");
                } else {
                    logger.info("消息发送确认失败:" + cause);
                }
            }
        });
        String uuid = UUID.randomUUID().toString();
        CorrelationData correlationId = new CorrelationData(uuid);
        template.convertAndSend("myExchange", "foo.bar", "Hello, world!", correlationId);
        Thread.sleep(1000);
    }
}
